<template>
	<view class="pageItem">
		<view class="main">
			<view class="goods">
				<image class="g_img" :src="realUrl(goods.logo)"></image>
				<view class="g_msg">
					<view class="g_tit">{{goods.title}}</view>
					<view class="g_price">
						{{goods.goods_score}}<image class="img" src="/static/other/diamond_mini.png" mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view class="card">
				<view class="c_tit">
					{{$t('diamond.delivery_information')}}
					<block v-if="type == '2'">
						<!-- <label v-if="status == '1'" class="status">{{$t('diamond.order_status1')}}</label> -->
						<label v-if="goods.status == '2'" class="status">{{$t('diamond.order_status2')}}</label>
						<label v-if="goods.status == '4'" class="status">{{$t('diamond.order_status3')}}</label>
					</block>
				</view>
				<view class="row">
					<view class="r_tit">{{$t('use.recipient')}}</view>
					<input class="r_inp" type="text" v-model="express_name" :placeholder="$t('use.no_txt_tip')" placeholder-class="input_no_txt" :disabled="type == '2'?true:false"/>
				</view>
				<view class="row">
					<view class="r_tit">{{$t('use.phone')}}</view>
					<input class="r_inp" type="text" v-model="express_phone" :placeholder="$t('use.no_txt_tip')" placeholder-class="input_no_txt" :disabled="type == '2'?true:false"/>
				</view>
				<view class="row">
					<view class="r_tit">{{$t('use.address')}}</view>
					<textarea class="r_long" type="text" v-model="express_address" :placeholder="$t('use.no_txt_tip')" placeholder-class="input_no_txt" :disabled="type == '2'?true:false"/></textarea>
				</view>
				<view class="row">
					<view class="r_tit">{{$t('use.remark')}}</view>
					<textarea class="r_long" type="text" v-model="user_note" :placeholder="$t('use.no_txt_tip')" placeholder-class="input_no_txt" :disabled="type == '2'?true:false"/></textarea>
				</view>
				<view class="row" v-if="type == '2'">
					<view class="r_tit">{{$t('use.tracking_number')}}</view>
					<view class="r_no">{{express_send_no}}</view>
					<view class="iconfont copy">&#xe6cd;</view>
				</view>
			</view>
		</view>
		<view class="_footer" v-if="type != 2">
			<view class="btn sub" @click="create_order">{{$t('diamond.exchange_now')}}</view>
		</view>
	</view>
</template>

<script>
	import helper from '@/common/helper';
	export default {
		data() {
			return {
				goods : {},
				express_name : '',
				express_phone : '',
				express_address : '',
				express_send_no : '',
				user_note : '',
				type:'1',    //1兑换 2查看
				status:'1'   //1待发货   2待收货   3已完成
			}
		},
		onLoad(e) {
			if(e.type){
				this.type = e.type;
			}
			
		},
		onShow(){
			let info = uni.getStorageSync('cur_goods');
			uni.setStorageSync('cur_goods','');
			this.goods = JSON.parse(info);
			
			if(this.type == 2){
				this.express_name = this.goods.express_name;
				this.express_phone = this.goods.express_phone;
				this.express_address = this.goods.express_address;
				this.user_note = this.goods.user_note;	
				this.express_send_no = this.goods.express_send_no;
			}
			console.log(this.goods)
		},
		methods: {
			create_order(){
				if(this.express_address == '' || this.express_phone == '' || this.express_address == ''){
					this.showMsg(this.$t('system.tip5'));
					return false;
				}
				uni.$u.throttle(this.real_create_order, 800)
			},
			real_create_order(){
				uni.showModal({
					title: this.$t('system.tip'),
					content: this.$t('system.tip6'),
					success:  (res) => {
						if (res.confirm) {
							uni.showLoading({
								mask: true
							});
							helper.Timer.start();
							 let url = this.site_url + 'api/auth/order/create_order';
							 let param = {
								 express_name : this.express_name,
								 express_phone : this.express_phone,
								 express_address : this.express_address,
								 user_note : this.user_note,
								 goods_id : this.goods.id
							 };
							 this.areq(url,param,'POST').then(res=>{
									 helper.Timer.stop();
									 let left_time = helper.Timer.getLeftTime(2000);
									 setTimeout(()=>{
									 	uni.hideLoading();
									 	if(res.code == 1){
											uni.$emit('auto_update');
									 		this.showMsg(this.$t('system.tip32'), 2000, true, 'success');
									 		//this.change_money = res.data.money;
									 		//this.mask = true;
									 		setTimeout(() => {
									 			this.backTo();
									 		}, 1500)
									 	}else{
									 		this.showMsg(res.msg);
									 	}
									 },left_time);	
									 
							 })
							
						} else if (res.cancel) {
							//console.log('用户点击取消');
						}
					}
				});
			},
			initData(){
				
				
			}
		}
	}
</script>

<style lang="scss">
.pageItem{
	padding-bottom: 22vw;
}
.main{
	width: 100%;
	padding: 4vw 4% 0;
}
.goods{
	@include card_style();
	display: flex;
	.g_img{
		width: 25vw;
		height: 26vw;
		border-radius: 1vw;
	}
	.g_msg{
		flex: 1;
		padding-left: 3vw;
		.g_tit{
			font-size: 4vw;
			font-weight: bold;
			padding-top: 2vw;
			color: $main_color5;
		}
		.g_price{
			padding-top: 5vw;
			font-size: 5vw;
			color: $price_color;
			font-weight: bold;
			display: flex;
			align-items: center;
			.img{
				width: 4vw;
				margin-left: 2vw
			}
		}
	}
}
.card{
	@include card_style();
	margin-top: 4vw;
	padding: 5vw;
	.c_tit{
		width: 100%;
		font-size: 4vw;
		color: $main_color5;
		font-weight: bold;
		padding-bottom: 2vw;
		.status{
			padding-left: 4vw;
			font-size: 3.8vw;
			font-weight: bold;
			color: $main_color_s2;
		}
	}
	.row{
		width: 100%;
		display: flex;
		align-items: flex-start;
		padding: 3vw 0;
		color: $main_color4;
		border-bottom: 1rpx solid #757575;
		.r_tit{
			width: 30vw;
			font-size: 3.6vw;
			line-height: 6vw;
			font-weight: bold;
			color: $main_color5;
		}
		.r_inp{
			flex: 1;
			padding: 0 2vw;
			line-height: 6vw;
			color: $main_color5;
		}
		.r_long{
			flex: 1;
			height: 20vw;
			padding: 0 2vw;
			line-height: 6vw;
		}
		.r_no{
			flex: 1;
			font-size: 3.3vw;
			font-weight: bold;
			line-height: 6vw;
			@include text_over_style(1);
		}
		.copy{
			font-size: 5vw;
			margin-left: 4vw;
			line-height: 6vw;
		}
	}
}
._footer{
	@include page_button();
	position: fixed;
	bottom: 0;
	height: 22vw;
	padding: 3vw 0 6vw;
	background: $main_bg_color;
}
</style>
